import { useState } from "react";

export default function Counter(props) {
    
    // 100%执行  但是useState的初始化不会再做了
    const [count, setCount] = useState(props.defaultValue || 0)
    const increase = () => {
        setCount(n => n + 1)
    }
    const decrease = () => {
        setCount(n => n - 1)
    }
    window.getCount = () => {
        console.log("count", count, setCount);
    }
    const handleClick = () => {
        console.log('click button')
    }

    return (
        <div onClick={() => console.log('click div')}>
            <button onClick={increase}>+</button>
            <span>{count}</span>
            <button onClick={decrease}>-</button>
            <button onClick={handleClick}>click button</button>
        </div>
    )
}